package com.situ.achievementsystem.util;

import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

public class JDBCUtil {

	private static ResourceBundle rb = ResourceBundle.getBundle("com.situ.achievementsystem.util.jdbc");
	private static String className = rb.getString("driver");
	private static String url = rb.getString("url");
	private static String user = rb.getString("user");
	private static String password = rb.getString("pass");
	
	static {
		try {
			Class.forName(className);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, user, password);
	}
	
	public static void close(Connection conn,Statement st,ResultSet rs) {

		try {
			if (rs != null) {
				rs.close();
				rs = null;
			}
			if (st != null) {
				st.close();
				st = null;
			}
			if (conn != null) {
				conn.close();
				conn = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void close(Connection connection , Statement statement) {
		close(connection,statement,null);
	}
	
	public static void main(String[] args) throws SQLException {
		Connection con  = JDBCUtil.getConnection();
		System.out.println(con);
		JDBCUtil.close(con,null);
//		Connection co = JDBCUtil.getConnection();
//		PreparedStatement st = co.prepareStatement("");
//		ResultSet rs = st.executeQuery();
//		JDBCUtil.close(con,st,rs);
	}
	
	private JDBCUtil() {
		
	}
	
}
